// 原型链继承: 子prototype = 父实例
// 缺陷：多实例对引用类型的操作会被篡改。
```
function Parent() {
  this.color = ['red', 'blue']
}
function Child() {}

Child.prototype = new Parent()
Child.prototype.constructor = Child

const child1 = new Child()
const child2 = new Child()
child1.color.push('green') // 对child1修改

console.log(child1.color) // ['red', 'blue', 'green']
console.log(child2.color) // ['red', 'blue', 'green']
```

// 构造函数继承：子类中 调用 父类.call(this)
// 缺点：只能父类的实例属性和方法，无法继承原型
```
function Parent() {
  this.color = ['red', 'blue']
}
function Child() {
  Parent.call(this)
}

const child1 = new Child()
const child2 = new Child()
child1.color.push('green') // 对child1修改

console.log(child1.color) // ['red', 'blue', 'green']
console.log(child2.color) // ['red', 'blue']
```


// 组合式继承：原型链+构造函数继承
// 缺点：原型和实例有重复属性/方法
// 原型上name: undefiend, 实例上name: '张三'
```
function Parent(name) {
  this.name = name
  this.color = ['red', 'blue']
}
function Child(name, age) {
  Parent.call(name)
  this.age = age
}

Child.prototype = new Parent()
Child.prototype.constructor = Child

const child = new Child('张三', 18)
```

// 寄生组合式继承
```
function initPrototype(Parent, Child) {
  const prototype = Object.create(Parent.prototype)
  Child.prototype = prototype
  prototype.constructor = Child
}

function Parent(name) {
  this.name = name
  this.color = ['red', 'blue']
}

function Child(name, age) {
  Parent.call(name)
  this.age = age
}

initPrototype(Parent, Child)

const child1 = new Child('张三', 18)
const child2 = new Child('Tom', 19)
child1.color.push('green') // 对child1修改

console.log(child1.color) // ['red', 'blue', 'green']
console.log(child2.color) // ['red', 'blue']
```
